using Gameplay.PVE.Utils;
using UnityEngine;

namespace Gameplay.PVE.Skill
{
    public class SkillShoot : SkillBase
    {
        private float startCastTime;
        private float bulletTime;
        private float shootStartTime;
        private float backPlayStartTime;
        
        protected override void Cast()
        {
            bulletTime = 0;
            shootStartTime = 0;
            unit.Play("Attack");
            startCastTime = TimeManager.logicTime;
        }

        protected override void Storage()
        {
            unit.Data.SetIsCanMove(false);
            unit.Play("Idle");
        }
        
        protected override void Recover()
        {
            base.Recover();
            unit.Play("Idle",1);
            unit.Data.SetIsInAttack(false);
            unit.Data.SetIsCanMove(true);
        }

        protected override bool CheckIsCanSkill()
        {
            return base.CheckIsCanSkill() && unit.Data.IsInAttack() && unit.Data.IsCanAttack();
        }

        protected override void CastEvent()
        {
            if (unit.Data.isDead)
            {
                unit.SetAnimatorSpeed(1);
                return;
            }
            /*if (TimeManager.logicTime - startCastTime < config.bulletStartTime)
            {
                return;
            }*/

            /*if (shootStartTime != 0 && TimeManager.logicTime - shootStartTime >= config.shootDuration)
            {
                unit.SetAnimatorSpeed(1);
                return;
            }

            if (TimeManager.logicTime - bulletTime >= config.shootDuration / config.bulletCount)
            {
                if (bulletTime == 0)
                {
                    //unit.Transmit(ETransmitType.PlayShootSound);
                    unit.SetAnimatorSpeed(0.2f);
                    shootStartTime = TimeManager.logicTime;
                }
                bulletTime = TimeManager.logicTime;
                for (int i = 0; i < config.bullets.Count; i++)
                {
                    var offset = GetBulletOffset((int)config.bullets[i].z);
                    var position = offset + unit.Data.position;
                    if (config.directorType == 4 || config.directorType == 0)//向targetList方向
                    {
                        CreateBulletByTargets(offset,(int)config.bullets[i].y);
                    }
                    else//向自身方向
                    {
                        CreateBulletByCertainForward(offset,(int)config.bullets[i].y);
                    }

                    if (unit.Data.leftAmmoCount > 0)
                    {
                        unit.Data.leftAmmoCount--;
                    }

                    if (unit.Data.leftAmmoCount == 0)
                    {
                        StartRecover();
                    }
                }
            }*/
        }
    }
}